from django.urls import converters


# 定义转换器
class UsernameConverter:
    regex = '[0-9a-zA-Z_]{5,20}'

    def to_python(self, value):
        return str(value)


# 手机号转换器
class MobileConverter:
    regex = '1[3-9]\d{9}'

    def to_python(self, value):
        return str(value)

# 自定义路由转换器匹配
class UUIDConverter:
    regex = '[\w-]+'

    def to_python(self, value):
        # to_python：将匹配结果传递到视图内部时使用
        return str(value)

    def to_url(self, value):
        return str(value)